//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import goodsItem from '../comm/goodsItem.vue';
import { scrollMixin } from "utils/mixin";
export default {
  name:'',
  //import引入的组件需要注入到对象中才能使用
  components: {
    goodsItem
  },
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      active:0,
      isLoadMore:true,
      presentArr:[
        {
          name:'转赠藏品',
          status:0,
          goodsList: [],
          page: 1,
          total_page: 0,
        },
        {
          name:'受赠藏品',
          status:1,
          goodsList: [],
          page: 1,
          total_page: 0,
        }
      ],
      presentList:[]
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    presentTab() {
      if (this.presentArr[this.active].page >= 2) {
        this.presentArr[this.active].goodsList = [];
      }
      if (this.presentArr[this.active].goodsList.length === 0) {
        this.isLoadMore = false;
        this.presentArr[this.active].page = 1;
        this.recordList();
      }
    },
    recordList() {
      let query = {
        has_transfer:this.active,
        page:this.presentArr[this.active].page
      }
      $http.get('plugin.collection-center.frontend.controllers.record.transfer-record', query, "加载中..").then(response => {
        if (response.result == 1) {
            let res = response.data;
            let list = res.record_list.data;
            this.isLoadMore = true;
            this.presentArr[this.active].total_page = res.record_list.last_page;
            if (!this.presentArr[this.active].total_page) {
              this.presentArr[this.active].page = 0;
            }
            this.presentArr[this.active].goodsList = list;
        } else {
          this.presentArr[this.active].page = this.presentArr[this.active].page - 1;
          this.isLoadMore = false;
          this.$dialog.alert({
            message: response.msg
          });
        }
      });
    },
     //获取更多数据
     getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.presentArr[this.active].page >= this.presentArr[this.active].total_page) {
        return;
      } else {
        this.presentArr[this.active].page = this.presentArr[this.active].page + 1;
        let query = {
          has_transfer:this.active,
          page:this.presentArr[this.active].page
        };
        $http.post("plugin.collection-center.frontend.controllers.record.transfer-record", query, "加载中").then(
          res => {
            this.isLoadMore = true;
            if (res.result === 1) {
              let data = res.data;
              let list = data.record_list.data;
              // this.isLoadMore = true;
              this.presentArr[this.active].goodsList = [...this.presentArr[this.active].goodsList, ...list];
            } else {
              this.presentArr[this.active].page = this.presentArr[this.active].page - 1;
              this.isLoadMore = false;
            }
          },
          function(response) {
            console.log("response", response);
            // error callback
          }
        );
      }
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
  
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
  
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {
    this.page = 1;
    this.presentArr.forEach((item,index) => {
      item['goodsList'] = [];
    });
    this.recordList();
  }, //如果页面有keep-alive缓存功能，这个函数会触发
  }